package 剑指offer_力扣版.Month07.day05字符串;

import java.util.ArrayList;
import java.util.List;

public class 不含重复字符的最长子串 {
    public int lengthOfLongestSubstring(String s) {
        int left = 0,right = 0;//滑动窗口起始和末尾位置
        int count = 0;//记录最大出现次数
        List<Character> list = new ArrayList<>();
        while (right < s.length()){
            while(left < right && list.contains(s.charAt(right))){
                list.remove(0);
                left++;
            }
            list.add(s.charAt(right));
            right++;
            count = Math.max(count,right - left + 1);
        }
        return count;
    }
}
